//
//  XCPhoneRegisController.m
//  TTLestening
//
//  Created by dllo on 16/4/9.
//  Copyright © 2016年 dilo. All rights reserved.
//

#import "XCPhoneRegisController.h"
#import "XCPhoneSignInController.h"
#import <AVOSCloud.h>
@interface XCPhoneRegisController ()
@property (weak, nonatomic) IBOutlet UITextField *userName;
@property (weak, nonatomic) IBOutlet UITextField *userCode;
@property (weak, nonatomic) IBOutlet UITextField *userEmail;
@property (weak, nonatomic) IBOutlet UITextField *userPhone;
@property (weak, nonatomic) IBOutlet UITextField *phonecode;

@end

@implementation XCPhoneRegisController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
     
    
}

- (IBAction)handleRegin:(id)sender {
    
    
    [AVOSCloud verifySmsCode:self.phonecode.text mobilePhoneNumber:self.userPhone.text callback:^(BOOL succeeded, NSError *error) {
        
        AVUser *user = [AVUser user];
        if (succeeded) {
            user.username = self.userName.text;
            user.password = self.userCode.text;
            user.email = self.userEmail.text;
            user.mobilePhoneNumber = self.userPhone.text;
            
            [user signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
                if (succeeded) {
                    // 注册成功
                    NSLog(@"注册成功");
                    
                    
                    XCPhoneSignInController *sign = [[XCPhoneSignInController alloc] init];
                    [self.navigationController pushViewController:sign animated:YES];
                    
                    
                } else {
                    // 失败的原因可能有多种，常见的是用户名已经存在。
                    NSLog(@"注册失败");
                    NSLog(@"%@", error);
                    
                    
                }
                
            }];
            
            
            
        } else {
            
            NSLog(@"%@", error);
            
            
        }
        
        
        
    }];
    
    
    
}

- (IBAction)phoneKey:(id)sender {
    
    
    
    [AVOSCloud requestSmsCodeWithPhoneNumber:self.userPhone.text callback:^(BOOL succeeded, NSError *error) {
        
        if(succeeded){
            //发送成功
            NSLog(@"发送验证码成功");
            
        } else{
            
            NSLog(@"%@", error);
            
        }
        
        //  NSLog(@"%@", error);
    }];
    
    
    
    
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
